import { Application } from "pixi.js";
import { emitter } from "../../eventEmitter";
import AddBone from "../../assets/cursors/AddBone.png";
import Rotate from "../../assets/cursors/Rotate.png";
import Move from "../../assets/cursors/Move.png";
import Scale from "../../assets/cursors/Scale.png";
import { ArmatureView } from "../views/ArmatureView";


export type CursorType = "transform" | "move" | "rotate" | "scale" | "createBone";
export class CursorManager {
    private _app: Application;
    private _armatureView: ArmatureView;
    constructor(app: Application, armatureView: ArmatureView) {
        this._app = app;
        this._armatureView = armatureView;
        this.registerStyle();
        this.registerEvent();
    }

    registerStyle() {
        //this._app.renderer.plugins.interaction.cursorStyles.default = "url('imgs/bunny.png'),auto";
        this._app.renderer.plugins.interaction.cursorStyles.customAddBone = `url('${AddBone}'),auto`;
        this._app.renderer.plugins.interaction.cursorStyles.customRotate = `url('${Rotate}'),auto`;
        this._app.renderer.plugins.interaction.cursorStyles.customMove = `url('${Move}'),auto`;
        this._app.renderer.plugins.interaction.cursorStyles.customScale = `url('${Scale}'),auto`;
    }

    changeStyle(type: CursorType) {
        switch (type) {
            case "move":
                this._armatureView.cursor = "customMove";
                break;

            case "createBone":
                this._armatureView.cursor = "customAddBone";
                break;

            case "transform":
                this._armatureView.cursor = "default";
                break;

            case "rotate":
                this._armatureView.cursor = "customRotate";
                break;

            case "scale":
                this._armatureView.cursor = "customScale";
                break;

            default:
                this._armatureView.cursor = "default";
                break;
        }
    }

    registerEvent() {
        emitter.on("changeCursor", (e) => {
            this.changeStyle(e);
        });
    }
}